<template>
  <!-- 气泡背景 -->
  <div class="bruce">
    <ul class="bubble-bgwall">
      <li>Register</li>
      <li>New</li>
      <li>Account</li>
      <li>Welcome</li>
      <li>Join</li>
      <li>Safe</li>
      <li>Modern</li>
      <li>Fast</li>
      <li>Smart</li>
      <li>Cloud</li>
    </ul>
  </div>

  <!-- 注册容器 -->
  <div class="register-container">
    <div class="register-box">
      <div class="register-header">
        <h1>创建账户</h1>
        <p class="subtitle">加入我们的管理平台</p>
        
        <!-- 开发者测试账号提示 -->
        <div class="dev-tips">
          <p class="dev-title">🧪 开发者测试账号</p>
          <p class="dev-account">邮箱验证码: 123456 (固定)</p>
        </div>
      </div>

      <form @submit.prevent="handleRegister" class="register-form">
        <!-- 用户名 -->
        <div class="form-group">
          <label for="username">用户名 <span class="required">*</span></label>
          <input 
            id="username" 
            v-model="formData.username" 
            type="text" 
            placeholder="请输入用户名（3-20个字符）" 
            required 
            :class="{ 'error': errors.username }"
          />
          <div v-if="errors.username" class="field-error">{{ errors.username }}</div>
        </div>

        <!-- 邮箱地址 -->
        <div class="form-group">
          <label for="email">邮箱地址 <span class="required">*</span></label>
          <input 
            id="email" 
            v-model="formData.email" 
            type="email" 
            placeholder="请输入邮箱地址（测试用test@example.com）" 
            required 
            :class="{ 'error': errors.email }"
          />
          <div v-if="errors.email" class="field-error">{{ errors.email }}</div>
        </div>

        <!-- 邮箱验证码 -->
        <div class="form-group">
          <label for="emailCode">邮箱验证码 <span class="required">*</span></label>
          <div class="code-container">
            <input 
              id="emailCode" 
              v-model="formData.emailCode" 
              type="text" 
              placeholder="请输入6位验证码（测试账号用123456）" 
              required 
              maxlength="6"
              :class="{ 'error': errors.emailCode }"
            />
            <button 
              type="button" 
              class="code-button" 
              @click="sendEmailCode"
              :disabled="emailCountdown > 0 || sendingCode"
            >
              <span v-if="emailCountdown > 0">{{ emailCountdown }}s后重发</span>
              <span v-else-if="sendingCode">发送中...</span>
              <span v-else>获取验证码</span>
            </button>
          </div>
          <div v-if="errors.emailCode" class="field-error">{{ errors.emailCode }}</div>
        </div>

        <!-- 图形验证码 -->
        <div class="form-group">
          <label for="captcha">图形验证码 <span class="required">*</span></label>
          <div class="captcha-container">
            <input 
              id="captcha" 
              v-model="formData.captcha" 
              type="text" 
              placeholder="请输入图形验证码" 
              required 
              :class="{ 'error': errors.captcha }"
            />
            <div class="captcha-wrapper">
              <div class="captcha-image" @click="refreshCaptcha">
                <canvas 
                  ref="captchaCanvas" 
                  width="120" 
                  height="40"
                  title="点击刷新验证码"
                ></canvas>
              </div>
              <p class="captcha-hint" @click="refreshCaptcha">看不清？换一张</p>
            </div>
          </div>
          <div v-if="errors.captcha" class="field-error">{{ errors.captcha }}</div>
        </div>

        <!-- 密码 -->
        <div class="form-group">
          <label for="password">密码 <span class="required">*</span></label>
          <div class="password-container">
            <input 
              id="password" 
              v-model="formData.password" 
              :type="showPassword ? 'text' : 'password'" 
              placeholder="请输入密码（6-20位）"
              required 
              :class="{ 'error': errors.password }"
            />
            <button 
              type="button" 
              class="eye-button" 
              @click="showPassword = !showPassword"
            >
              <span v-if="showPassword">👁️</span>
              <span v-else>👁️‍🗨️</span>
            </button>
          </div>
          <div v-if="errors.password" class="field-error">{{ errors.password }}</div>
        </div>

        <!-- 确认密码 -->
        <div class="form-group">
          <label for="confirmPassword">确认密码 <span class="required">*</span></label>
          <div class="password-container">
            <input 
              id="confirmPassword" 
              v-model="formData.confirmPassword" 
              :type="showConfirmPassword ? 'text' : 'password'" 
              placeholder="请再次输入密码"
              required 
              :class="{ 'error': errors.confirmPassword }"
            />
            <button 
              type="button" 
              class="eye-button" 
              @click="showConfirmPassword = !showConfirmPassword"
            >
              <span v-if="showConfirmPassword">👁️</span>
              <span v-else>👁️‍🗨️</span>
            </button>
          </div>
          <div v-if="errors.confirmPassword" class="field-error">{{ errors.confirmPassword }}</div>
        </div>

        <!-- 用户协议 -->
        <div class="form-group">
          <div class="agreement-section" :class="{ 'agreement-error': errors.agreement }">
            <div class="agreement-box">
              <div class="agreement">
                <input id="agreement" type="checkbox" v-model="formData.agreement" required />
                <label for="agreement">
                  我已阅读并同意
                  <a href="#" @click.prevent="showUserAgreement" class="agreement-link">《用户协议》</a>
                  和
                  <a href="#" @click.prevent="showPrivacyPolicy" class="agreement-link">《隐私政策》</a>
                </label>
              </div>
              <div v-if="errors.agreement" class="agreement-error-tip">
                <i class="error-icon">⚠️</i>
                <span class="error-text">{{ errors.agreement }}</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 按钮 -->
        <div class="button-container">
          <button type="submit" class="register-button" :disabled="loading">
            <span v-if="!loading">注册</span>
            <span v-else>注册中...</span>
          </button>
          <button type="button" @click="goToLogin" class="login-link-button">
            已有账号？立即登录
          </button>
        </div>

        <div v-if="error" class="error-message">
          {{ error }}
        </div>
      </form>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, reactive } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';
import { authApi } from '@/api/auth';

const router = useRouter();
const captchaCanvas = ref(null);

// 表单数据
const formData = reactive({
  username: '',
  email: '',
  emailCode: '',
  captcha: '',
  password: '',
  confirmPassword: '',
  agreement: false
});

// 错误信息
const errors = reactive({
  username: '',
  email: '',
  emailCode: '',
  captcha: '',
  password: '',
  confirmPassword: '',
  agreement: ''
});

const error = ref('');
const loading = ref(false);
const showPassword = ref(false);
const showConfirmPassword = ref(false);
const sendingCode = ref(false);
const emailCountdown = ref(0);
const captchaText = ref('');

let countdownInterval = null;

// 检查是否是开发者测试账号
const isDeveloperAccount = (email) => {
  return email && email.startsWith('test@');
};

// 生成随机图形验证码
const generateCaptcha = () => {
  const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  let result = '';
  for (let i = 0; i < 4; i++) {
    result += chars.charAt(Math.floor(Math.random() * chars.length));
  }
  captchaText.value = result;
  drawCaptcha();
};

// 绘制验证码
const drawCaptcha = () => {
  if (!captchaCanvas.value) return;
  
  const canvas = captchaCanvas.value;
  const ctx = canvas.getContext('2d');
  
  // 清空画布
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  
  // 设置背景
  const gradient = ctx.createLinearGradient(0, 0, canvas.width, canvas.height);
  gradient.addColorStop(0, '#f0f0f0');
  gradient.addColorStop(1, '#e8e8e8');
  ctx.fillStyle = gradient;
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  
  // 绘制干扰线
  for (let i = 0; i < 3; i++) {
    ctx.strokeStyle = `hsl(${Math.random() * 360}, 50%, 70%)`;
    ctx.lineWidth = 1;
    ctx.beginPath();
    ctx.moveTo(Math.random() * canvas.width, Math.random() * canvas.height);
    ctx.lineTo(Math.random() * canvas.width, Math.random() * canvas.height);
    ctx.stroke();
  }
  
  // 绘制干扰点
  for (let i = 0; i < 20; i++) {
    ctx.fillStyle = `hsl(${Math.random() * 360}, 50%, 70%)`;
    ctx.beginPath();
    ctx.arc(
      Math.random() * canvas.width,
      Math.random() * canvas.height,
      1,
      0,
      2 * Math.PI
    );
    ctx.fill();
  }
  
  // 绘制验证码文字
  const text = captchaText.value;
  const fontSize = 20;
  ctx.font = `${fontSize}px Arial`;
  ctx.textAlign = 'center';
  ctx.textBaseline = 'middle';
  
  for (let i = 0; i < text.length; i++) {
    const char = text[i];
    const x = (canvas.width / text.length) * (i + 0.5);
    const y = canvas.height / 2 + (Math.random() - 0.5) * 8;
    const angle = (Math.random() - 0.5) * 0.4;
    
    ctx.save();
    ctx.translate(x, y);
    ctx.rotate(angle);
    ctx.fillStyle = `hsl(${Math.random() * 360}, 70%, 40%)`;
    ctx.fillText(char, 0, 0);
    ctx.restore();
  }
};

// 刷新验证码
const refreshCaptcha = () => {
  generateCaptcha();
  formData.captcha = '';
  errors.captcha = '';
};

// 发送邮箱验证码
const sendEmailCode = async () => {
  // 先验证邮箱
  if (!validateEmail()) {
    return;
  }

  try {
    sendingCode.value = true;
    
    // 检查是否是开发者测试账号
    if (isDeveloperAccount(formData.email)) {
      // 开发者测试账号，模拟发送
      await new Promise(resolve => setTimeout(resolve, 1000));
      ElMessage.success('验证码已发送（开发者测试账号，验证码为123456）');
    } else {
      // 普通用户，调用后端API
      await authApi.sendEmailCode(formData.email);
      ElMessage.success('验证码已发送，请查收邮箱');
    }
    
    // 开始倒计时
    emailCountdown.value = 60;
    countdownInterval = setInterval(() => {
      emailCountdown.value--;
      if (emailCountdown.value <= 0) {
        clearInterval(countdownInterval);
      }
    }, 1000);
    
  } catch (err) {
    let errorMsg = '验证码发送失败，请重试';
    
    // 处理常见错误类型
    if (err.code === 'NETWORK_ERROR' || err.message === 'Network Error') {
      errorMsg = '网络连接失败，请检查网络后重试';
    } else if (err.response?.status === 429) {
      errorMsg = '发送过于频繁，请稍后再试';
    } else if (err.response?.status === 400) {
      errorMsg = '邮箱格式不正确';
    } else if (err.response?.data?.message) {
      errorMsg = err.response.data.message;
    } else if (err.message) {
      errorMsg = err.message;
    }
    
    ElMessage.error(errorMsg);
  } finally {
    sendingCode.value = false;
  }
};

// 表单验证
const validateUsername = () => {
  const username = formData.username.trim();
  if (!username) {
    errors.username = '用户名不能为空';
    return false;
  }
  if (username.length < 3 || username.length > 20) {
    errors.username = '用户名长度应为3-20个字符';
    return false;
  }
  if (!/^[a-zA-Z0-9_\u4e00-\u9fa5]+$/.test(username)) {
    errors.username = '用户名只能包含字母、数字、下划线和中文';
    return false;
  }
  errors.username = '';
  return true;
};

const validateEmail = () => {
  const email = formData.email.trim();
  if (!email) {
    errors.email = '邮箱地址不能为空';
    return false;
  }
  // 开发者测试账号验证
  if (email.startsWith('test@')) {
    if (!/^test@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)) {
      errors.email = '开发者测试账号格式：test@example.com';
      return false;
    }
  } else {
    // 普通用户邮箱验证
    if (!/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/.test(email)) {
      errors.email = '请输入正确的邮箱地址';
      return false;
    }
  }
  errors.email = '';
  return true;
};

const validateEmailCode = () => {
  const emailCode = formData.emailCode.trim();
  if (!emailCode) {
    errors.emailCode = '验证码不能为空';
    return false;
  }
  if (!/^\d{6}$/.test(emailCode)) {
    errors.emailCode = '请输入6位数字验证码';
    return false;
  }
  
  // 开发者测试账号验证码固定为123456
  if (isDeveloperAccount(formData.email)) {
    if (emailCode !== '123456') {
      errors.emailCode = '开发者测试账号验证码为：123456';
      return false;
    }
  }
  // 注意：普通用户的验证码验证应该由后端处理
  
  errors.emailCode = '';
  return true;
};

const validateCaptcha = () => {
  const captcha = formData.captcha.trim();
  if (!captcha) {
    errors.captcha = '图形验证码不能为空';
    return false;
  }
  if (captcha.toLowerCase() !== captchaText.value.toLowerCase()) {
    errors.captcha = '图形验证码错误';
    return false;
  }
  errors.captcha = '';
  return true;
};

const validatePassword = () => {
  const password = formData.password;
  if (!password) {
    errors.password = '密码不能为空';
    return false;
  }
  if (password.length < 6 || password.length > 20) {
    errors.password = '密码长度应为6-20位';
    return false;
  }
  if (!/^(?=.*[a-zA-Z])(?=.*\d)/.test(password)) {
    errors.password = '密码必须包含字母和数字';
    return false;
  }
  errors.password = '';
  return true;
};

const validateConfirmPassword = () => {
  const confirmPassword = formData.confirmPassword;
  if (!confirmPassword) {
    errors.confirmPassword = '确认密码不能为空';
    return false;
  }
  if (confirmPassword !== formData.password) {
    errors.confirmPassword = '两次输入的密码不一致';
    return false;
  }
  errors.confirmPassword = '';
  return true;
};

const validateAgreement = () => {
  if (!formData.agreement) {
    errors.agreement = '请阅读并同意用户协议和隐私政策';
    return false;
  }
  errors.agreement = '';
  return true;
};

// 提交注册
const handleRegister = async () => {
  // 清空之前的错误
  Object.keys(errors).forEach(key => {
    errors[key] = '';
  });
  error.value = '';

  // 验证所有字段
  const validations = [
    validateUsername(),
    validateEmail(),
    validateEmailCode(),
    validateCaptcha(),
    validatePassword(),
    validateConfirmPassword(),
    validateAgreement()
  ];

  if (!validations.every(Boolean)) {
    return;
  }

  try {
    loading.value = true;

    // 检查是否是开发者测试账号
    if (isDeveloperAccount(formData.email)) {
      // 开发者测试账号，模拟注册成功
      await new Promise(resolve => setTimeout(resolve, 2000));
      
      // 保存注册用户信息到localStorage，供登录时使用
      const registeredUsers = JSON.parse(localStorage.getItem('registeredTestUsers') || '[]');
      const newUser = {
        id: Date.now(),
        username: formData.username,
        email: formData.email,
        password: formData.password, // 保存密码用于登录验证
        registeredAt: new Date().toISOString()
      };
      
      // 检查是否已存在相同用户名
      const existingUserIndex = registeredUsers.findIndex(u => u.username === formData.username);
      if (existingUserIndex >= 0) {
        // 更新现有用户
        registeredUsers[existingUserIndex] = newUser;
      } else {
        // 添加新用户
        registeredUsers.push(newUser);
      }
      
      localStorage.setItem('registeredTestUsers', JSON.stringify(registeredUsers));
      
      // 保存最近注册的用户名，用于登录页面提示
      localStorage.setItem('lastRegisteredUser', formData.username);
      
      ElMessage.success('开发者测试账号注册成功！请使用用户名登录');
      router.push('/login');
    } else {
      // 普通用户，调用后端注册API
      await authApi.register({
        username: formData.username,
        email: formData.email,
        emailCode: formData.emailCode,
        password: formData.password,
        captchaCode: formData.captcha
      });
      ElMessage.success('注册成功！请登录');
      router.push('/login');
    }
    
  } catch (err) {
    let errorMsg = '注册失败，请重试';
    
    // 处理常见错误类型
    if (err.code === 'NETWORK_ERROR' || err.message === 'Network Error') {
      errorMsg = '网络连接失败，请检查网络后重试';
    } else if (err.response?.status === 409) {
      errorMsg = '用户名或邮箱已存在';
    } else if (err.response?.status === 400) {
      errorMsg = '提交的信息有误，请检查后重试';
    } else if (err.response?.status === 422) {
      errorMsg = '验证码错误或已过期';
    } else if (err.response?.status === 500) {
      errorMsg = '服务器错误，请稍后重试';
    } else if (err.response?.data?.message) {
      errorMsg = err.response.data.message;
    } else if (err.message && err.message !== 'Network Error') {
      errorMsg = err.message;
    }
    
    error.value = errorMsg;
    ElMessage.error(errorMsg);
    // 刷新验证码
    refreshCaptcha();
  } finally {
    loading.value = false;
  }
};

// 跳转到登录页
const goToLogin = () => {
  router.push('/login');
};

// 显示用户协议
const showUserAgreement = () => {
  ElMessage.info('用户协议功能开发中...');
};

// 显示隐私政策
const showPrivacyPolicy = () => {
  ElMessage.info('隐私政策功能开发中...');
};

onMounted(() => {
  generateCaptcha();
});
</script>

<style scoped>
/* 全局样式重置 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

/* 气泡背景样式 */
.bruce {
  height: 100vh;
  width: 100vw;
  background-image: linear-gradient(270deg, #4facfe, #00f2fe);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
  overflow: hidden;
}

.bubble-bgwall {
  overflow: hidden;
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  list-style: none;
}

.bubble-bgwall li {
  display: flex;
  position: absolute;
  bottom: -200px;
  justify-content: center;
  align-items: center;
  border-radius: 10px;
  width: 50px;
  height: 50px;
  background-color: rgba(255, 255, 255, 0.15);
  color: #ccc;
  font-size: 14px;
  font-weight: 500;
  animation: bubble 15s infinite;
}

.bubble-bgwall li:nth-child(1) {
  left: 10%;
}

.bubble-bgwall li:nth-child(2) {
  left: 20%;
  width: 90px;
  height: 90px;
  animation-duration: 7s;
  animation-delay: 2s;
}

.bubble-bgwall li:nth-child(3) {
  left: 25%;
  animation-delay: 4s;
}

.bubble-bgwall li:nth-child(4) {
  left: 40%;
  width: 60px;
  height: 60px;
  background-color: rgba(255, 255, 255, 0.3);
  animation-duration: 8s;
}

.bubble-bgwall li:nth-child(5) {
  left: 70%;
}

.bubble-bgwall li:nth-child(6) {
  left: 80%;
  width: 120px;
  height: 120px;
  background-color: rgba(255, 255, 255, 0.2);
  animation-delay: 3s;
}

.bubble-bgwall li:nth-child(7) {
  left: 32%;
  width: 160px;
  height: 160px;
  animation-delay: 2s;
}

.bubble-bgwall li:nth-child(8) {
  left: 55%;
  width: 40px;
  height: 40px;
  font-size: 12px;
  animation-duration: 15s;
  animation-delay: 4s;
}

.bubble-bgwall li:nth-child(9) {
  left: 25%;
  width: 40px;
  height: 40px;
  background-color: rgba(255, 255, 255, 0.3);
  font-size: 12px;
  animation-duration: 12s;
  animation-delay: 2s;
}

.bubble-bgwall li:nth-child(10) {
  left: 85%;
  width: 160px;
  height: 160px;
  animation-delay: 5s;
}

@keyframes bubble {
  0% {
    opacity: 0.5;
    transform: translateY(0) rotate(45deg);
  }
  25% {
    opacity: 0.75;
    transform: translateY(-400px) rotate(90deg);
  }
  50% {
    opacity: 1;
    transform: translateY(-600px) rotate(135deg);
  }
  100% {
    opacity: 0;
    transform: translateY(-1000px) rotate(180deg);
  }
}

/* 注册容器 */
.register-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  z-index: 1000;
  animation: fadeIn 0.6s ease;
}

/* 注册框 */
.register-box {
  background: white;
  border-radius: 15px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
  width: 100%;
  overflow: hidden;
  backdrop-filter: blur(10px);
}

/* 注册头部 */
.register-header {
  padding: 35px 30px 25px;
  text-align: center;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: white;
  position: relative;
  overflow: hidden;
}

.register-header::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(45deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
  pointer-events: none;
}

.register-header h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.register-header .subtitle {
  font-size: 14px;
  opacity: 0.9;
  position: relative;
  z-index: 1;
}

/* 开发提示样式 */
.dev-tips {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 15px;
  margin-top: 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  z-index: 1;
}

.dev-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
  color: #fff;
}

.dev-account {
  font-size: 12px;
  margin: 4px 0;
  color: rgba(255, 255, 255, 0.9);
  font-family: monospace;
}

.dev-note {
  font-size: 11px;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.8);
  font-style: italic;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding-top: 8px;
}

/* 注册表单 */
.register-form {
  padding: 30px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
  font-size: 14px;
}

.required {
  color: #ff4757;
}

.form-group input {
  width: 100%;
  padding: 12px 15px;
  border: 1px solid #e1e8ed;
  border-radius: 8px;
  font-size: 16px;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.form-group input:focus {
  border-color: #4facfe;
  outline: none;
  box-shadow: 0 0 0 2px rgba(79, 172, 254, 0.2);
}

.form-group input:hover {
  border-color: #4facfe;
  box-shadow: 0 2px 12px rgba(79, 172, 254, 0.2);
}

.form-group input.error {
  border-color: #ff4757;
  box-shadow: 0 0 0 2px rgba(255, 71, 87, 0.2);
}

.field-error {
  color: #ff4757;
  font-size: 12px;
  margin-top: 5px;
}

/* 验证码和密码容器 */
.code-container,
.captcha-container,
.password-container {
  position: relative;
  display: flex;
  gap: 10px;
}

.code-container input,
.captcha-container input {
  flex: 1;
}

.code-button {
  padding: 12px 16px;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  min-width: 120px;
}

.code-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #00f2fe, #4facfe);
  transform: translateY(-1px);
}

.code-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* 图形验证码 */
.captcha-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.captcha-image {
  cursor: pointer;
  border: 1px solid #e1e8ed;
  border-radius: 8px;
  overflow: hidden;
  transition: all 0.3s ease;
  margin-bottom: 5px;
}

.captcha-image:hover {
  border-color: #4facfe;
  transform: scale(1.02);
}

.captcha-image canvas {
  display: block;
  background: #f8f9fa;
}

.captcha-hint {
  font-size: 11px;
  color: #666;
  margin: 0;
  cursor: pointer;
  transition: color 0.3s ease;
  text-align: center;
}

.captcha-hint:hover {
  color: #4facfe;
}

/* 密码眼睛图标 */
.eye-button {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: #666;
  padding: 4px;
  font-size: 16px;
  transition: color 0.3s ease;
}

.eye-button:hover {
  color: #4facfe;
}

/* 用户协议 */
.agreement {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.agreement input[type="checkbox"] {
  width: auto;
  margin: 0;
  flex-shrink: 0;
  margin-top: 2px;
}

.agreement label {
  margin-bottom: 0;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  line-height: 1.5;
}

.agreement-link {
  color: #4facfe;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.3s ease;
}

.agreement-link:hover {
  color: #00f2fe;
  text-decoration: underline;
}

/* 用户协议优雅错误提示样式 */
.agreement-section {
  transition: all 0.3s ease;
  border-radius: 12px;
  padding: 4px;
}

.agreement-section.agreement-error {
  background: linear-gradient(135deg, rgba(255, 87, 51, 0.05), rgba(255, 87, 51, 0.02));
  border: 1px solid rgba(255, 87, 51, 0.2);
  box-shadow: 0 2px 8px rgba(255, 87, 51, 0.1);
}

.agreement-box {
  background: white;
  border-radius: 8px;
  padding: 16px;
  position: relative;
}

.agreement-error .agreement-box {
  border: 1px solid rgba(255, 87, 51, 0.15);
}

.agreement-error-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, #fff5f5, #fef2f2);
  border: 1px solid #fed7d7;
  border-radius: 8px;
  animation: gentleShake 0.6s ease-in-out;
}

.error-icon {
  font-size: 16px;
  filter: hue-rotate(10deg);
  animation: pulse 2s infinite;
}

.error-text {
  color: #e53e3e;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

/* 按钮容器 */
.button-container {
  margin-top: 30px;
}

/* 注册按钮 */
.register-button {
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
  margin-bottom: 15px;
}

.register-button:hover:not(:disabled) {
  background: linear-gradient(135deg, #00f2fe, #4facfe);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(79, 172, 254, 0.4);
}

.register-button:disabled {
  opacity: 0.8;
  cursor: not-allowed;
  transform: none;
}

/* 登录链接按钮 */
.login-link-button {
  width: 100%;
  padding: 14px 20px;
  background: white;
  color: #4facfe;
  border: 2px solid #4facfe;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-link-button:hover {
  background: #4facfe;
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(79, 172, 254, 0.3);
}

/* 错误消息 */
.error-message {
  margin-top: 20px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #ffebee, #ffcdd2);
  color: #c62828;
  border-radius: 8px;
  text-align: center;
  font-size: 14px;
  border: 1px solid #ef9a9a;
  animation: shake 0.5s ease;
}

/* 动画 */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes gentleShake {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-1px); }
  75% { transform: translateY(1px); }
}

@keyframes pulse {
  0%, 100% { 
    transform: scale(1);
    opacity: 1;
  }
  50% { 
    transform: scale(1.1);
    opacity: 0.8;
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .register-container {
    width: 95vw;
    max-height: 95vh;
  }
  
  .register-header {
    padding: 25px 20px 20px;
  }
  
  .register-form {
    padding: 20px;
  }
  
  .code-container,
  .captcha-container {
    flex-direction: column;
  }
  
  .code-button {
    min-width: auto;
  }
  
  .captcha-wrapper {
    width: 100%;
    margin-top: 10px;
  }
  
  .agreement-section {
    padding: 2px;
  }
  
  .agreement-box {
    padding: 12px;
  }
  
  .agreement-error-tip {
    padding: 8px 10px;
    font-size: 12px;
  }
}

@media (max-width: 480px) {
  .bubble-bgwall li {
    display: none;
  }
  
  .bubble-bgwall li:nth-child(1),
  .bubble-bgwall li:nth-child(3),
  .bubble-bgwall li:nth-child(5) {
    display: flex;
  }
  
  .register-container {
    width: 98vw;
    max-height: 98vh;
  }
}

/* 滚动条样式 */
.register-container::-webkit-scrollbar {
  width: 6px;
}

.register-container::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}

.register-container::-webkit-scrollbar-thumb {
  background: rgba(79, 172, 254, 0.5);
  border-radius: 3px;
}

.register-container::-webkit-scrollbar-thumb:hover {
  background: rgba(79, 172, 254, 0.7);
}
</style>
